﻿<!-- 考试管理-监考安排-补考 -->
<template>
    <div>
        <div class="btn-add">
            <button type="button" class="btn btn-success btn-lg" @click="apks()"><i class="iconfont icon-chenggong ft12 mr5"></i>安排监考</button>
            <button type="button" class="btn btn-danger btn-lg" @click="qxjk()"><i class="iconfont icon-chexiao ft12 mr5"></i>取消监考</button>
        </div>

        <el-row :gutter="20" style="height:100px;padding:20px;">

            <el-col :span="3">
                <div class="input-group" style="margin-bottom:10PX;">
                    <div class="input-group-btn">
                        <button type="button" style="height: 34px;min-width:80PX" class="btn btn-primary  dropdown-toggle">考试类别</button>
                    </div>
                    <el-select placeholder="考试类别" size="mini" v-model="query.lx" class="form-control filter" style="height: 34px;padding:0px">
                        <el-option label="补考" value="补考"></el-option>
                        <el-option label="期末考试" value="期末考试"></el-option>

                    </el-select>

                </div>
            </el-col>
            <el-col :span="4">
                <div class="input-group" style="margin-bottom:10PX;">
                    <div class="input-group-btn">
                        <button type="button" style="height: 34px;min-width:80PX" class="btn btn-primary  dropdown-toggle">校区</button>
                    </div>
                    <base-xiaoq :pzoption="query.xiaoq"></base-xiaoq>

                </div>
            </el-col>
            <el-col :span="4">
                <div class="input-group" style="margin-bottom:10PX;">
                    <div class="input-group-btn">
                        <button type="button" style="height: 34px;min-width:80PX" class="btn btn-primary  dropdown-toggle">考试学期</button>
                    </div>
                    <base-xq :pzoption="query.xq"></base-xq>

                </div>
            </el-col>
            <el-col :span="6">
                <div class="input-group" style="margin-bottom:10PX;">
                    <div class="input-group-btn">
                        <button type="button" style="height: 34px;min-width:80PX" class="btn btn-primary  dropdown-toggle">班级系部</button>
                    </div>
                    <base-xb :pzoption="query.xb" isqx isjx isdx></base-xb>
                </div>
            </el-col>
            <el-col :span="4">
                <div class="input-group hide" style="margin-bottom:10PX;">
                    <div class="input-group-btn">
                        <button type="button" style="height: 34px;min-width:80PX" class="btn btn-default  dropdown-toggle">课程安排情况</button>
                    </div>
                    <el-select placeholder="课程安排情况" size="mini" v-model="query.apqk" class="form-control filter" style="height: 34px;padding:0px">
                        <el-option label="全部" value=""></el-option>
                        <el-option label="待安排" value="已安排"></el-option>
                        <el-option label="已安排" value="已安排"></el-option>

                    </el-select>

                </div>
            </el-col>
            <el-col :span="6">
            </el-col>
        </el-row>

        <el-row :gutter="20" style="padding:20px;   padding-top: 0px;">
            <el-col :span="8">

                <p class="text-danger" style="margin-bottom:5px">第一步：选择考试时间</p>
                <pl-table class="qjTable" :data="sjdata" v-loading="loading" height="450px" :row-style="{height:'20px'}" :cell-style="{padding:'0px'}" element-loading-background="rgba(0, 0, 0, 0.8)" stripe border fit use-virtual big-data-checkbox>

                    <pl-table-column prop="sjxx" label="时间" sortable>
                        <template slot-scope="scope">
                            <span>{{scope.row.sjxx}}</span>
                        </template>
                    </pl-table-column>
                    <pl-table-column prop="score" width="100" label="考场数量" sortable>
                    </pl-table-column>
                    <pl-table-column label="选中"
                                     width="120">
                        <template slot-scope="scope">
                            <el-radio @change="selchangesj(scope.row)" v-model="rselsj" :label="scope.row.sj"></el-radio>
                        </template>
                    </pl-table-column>
                </pl-table>

            </el-col>
            <el-col :span="16">
                <p class="text-danger hide" style="margin-bottom:5px">第二步：选择需要安排考试的考场</p>
                <button type="button" class="btn btn-info ml10" @click="dykcmd()"><i class="iconfont icon-chexiao ft12 mr5"></i>打印考场名单</button>

                <base-table :pzoption="tableop" @selection-change="rychange">
                </base-table>
            </el-col>
        </el-row>


        <div class="modal fade dx" id="DModal" role="dialog">
            <div class="modal-dialog" role="document" style="width: 1100px">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">
                            安排监考老师
                        </h4>
                    </div>
                    <div class="modal-body">
                        <el-alert show-icon style="width:96%;margin:20px" title="注意事项" type="warning" description="通过设置相关属性，快速安排会将勾选的教师随机分配到没有监考老师的考场中去,点击快速安排后一定要点击确认安排，才会正式生效">
                        </el-alert>
                        <el-tag style="margin-left: 20px; margin-bottom: 5px;font-size: 14px;" type="success">考试时间：{{selsj.sjxx}}</el-tag>


                        <el-row :gutter="20" style="padding:20px">

                            <el-col :span="12">

                                <el-table class="qjTable" :data="tableop.multipleSelection" height="430px" :row-style="{height:'30px'}" :cell-style="{padding:'5px'}" element-loading-background="rgba(0, 0, 0, 0.8)" stripe border fit use-virtual big-data-checkbox>

                                    <el-table-column prop="bkjse" label="考场" sortable>
                                        <template slot-scope="scope">
                                            <span>{{scope.row.bkjse}}</span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="kcs" label="考试课程">
                                    </el-table-column>
                                    <el-table-column prop="tempjkjs" label="监考教师">
                                    </el-table-column>
                                    <el-table-column label="清除"
                                                     width="60">
                                        <template slot-scope="scope">
                                            <i class="el-icon-delete" @click="clearjs(scope.row)"></i>
                                        </template>
                                    </el-table-column>
                                </el-table>

                            </el-col>
                            <el-col :span="12">
                                <div class="input-group mb5">
                                    <div class="input-group-btn">
                                        <button type="button" style="height: 34px;min-width:80PX" class="btn btn-default  dropdown-toggle">添加监考老师</button>
                                    </div>
                                    <base-js :pzoption="js" isdx></base-js>
                                    <span class="input-group-btn">
                                        <button class="btn btn-info" style="height: 34px;" @click="addjkls()" type="button">确定</button>
                                    </span>
                                </div>
                                <div class="input-group" style="width:520PX;margin-bottom:10PX;">
                                    <div class="input-group-btn">
                                        <button type="button" style="min-width:120PX;height: 34px;" class="btn btn-info  dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">搜索</button>
                                    </div>
                                    <el-input style="height: 34px;border-left-width: 0px;width:250px" size="medium" placeholder="输入教师搜索数据" v-model="seastrjs" clearable></el-input>


                                </div>
                                <el-table class="qjTable" :data="comjsdata" @selection-change="funseljs" height="400px" :cell-style="{padding:'5px'}" element-loading-background="rgba(0, 0, 0, 0.8)" stripe border fit use-virtual big-data-checkbox>
                                    <el-table-column label="监考教师库,第一次使用时请先完善监考老师库">
                                        <pl-table-column type="selection" width="45" fixed="left">
                                        </pl-table-column>
                                        <el-table-column type="index"
                                                         width="60">
                                        </el-table-column>
                                        <el-table-column prop="jsmc" label="教师名称" sortable>
                                            <template slot-scope="scope">
                                                <span>{{scope.row.jsdm}}-{{scope.row.jsmc}}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="jkcs" label="监考次数" sortable>
                                        </el-table-column>
                                        <el-table-column label="删除"
                                                         width="80">
                                            <template slot-scope="scope">
                                                <el-button @click.native.prevent="deleteRow(scope.$index, seljs)" type="text" size="small">删除</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table-column>
                                </el-table>
                            </el-col>
                        </el-row>
                        <div>
                            <el-form :inline="true" class="demo-form-inline" style="  margin-left: 20px;">

                                <el-form-item label="单个考场人数">
                                    <el-select v-model="kcrs" placeholder="人数">
                                        <el-option label="1人" value="1"></el-option>
                                        <el-option label="2人" value="2"></el-option>
                                    </el-select>
                                </el-form-item>

                            </el-form>
                            <button class="btn btn-info " style="height: 34px;margin-left:20px" @click="ksfp()" type="button">快速安排</button>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-success" @click="SaveData()">确认安排</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    module.exports = {
        props: ['pdata'],
        components: {
            'base-table': httpVueLoader('/ViewV5/Base/Vue/Table.vue'),
            'base-xq': httpVueLoader('/ViewV5/AppPage/QJJW/component/conxq.vue'),
            'base-xb': httpVueLoader('/ViewV5/AppPage/QJJW/component/conxb.vue?v=2'),
            'base-js': httpVueLoader('/ViewV5/AppPage/QJJW/component/conjs.vue?v=1'),
            'base-xiaoq': httpVueLoader('/ViewV5/AppPage/QJJW/component/conxiaoq.vue')
        },
        data: function () {
            return {
                search: "",
                seastrjs: "",
                kcdm: "",
                jssl: 0,
                alldata: [],//学生数据
                kcdata: [],//课程
                sjdata: [],//时间
                jsdata: [],//教师
                selsj: {},//选中时间
                seljs: [],//监考教师库
                jsks: [], //选中监考教师
                rselsj: "",
                rseljs: "",
                kcrs: "2",
                loading: false,
                query: {
                    lx: "补考",
                    qrzt: "",
                    apqk: "",
                    xb: { value: [] },
                    xq: { value: "" },
                    xiaoq: { value: "" }
                },
                lsxb: { value: "" },
                js: { value: [] },
                seljc: { jcmc: "", isbn: "" },
                tableop: {
                    title: "考场信息",
                    issel: true,
                    iscz: false,
                    height: 460,
                    isxh: true,
                    dataset: [],
                    loading: false,
                    multipleSelection: [],
                    collist: [
                        { colid: "bkjse", colname: "考场", isshow: true, istip: true },
                        { colid: "kssj", colname: "考试时间", isshow: false, istip: true },
                        { colid: "sj", colname: "具体时间", isshow: true, istip: true },
                        { colid: "bjs", colname: "考试班级", isshow: true, istip: true },
                        { colid: "kcs", colname: "考试课程", isshow: true, istip: true },
                        { colid: "jkjs", colname: "监考教师", isshow: true, istip: true, nosort: true }
                    ]
                }
            }
        },
        computed: {
            kcs: function () {
                var kcs = "";
                _.forEach(this.tableop.multipleSelection, function (obj) {
                    if (kcs.indexOf(obj.bkjse) == -1) {
                        kcs = kcs + obj.bkjse + ",";
                    }
                })
                return kcs;
            },
            comjsdata: function () {
                var pro = this;
                if (pro.seastrjs) {
                    return _.filter(pro.seljs, function (obj) {
                        return (obj.jsmc.indexOf(pro.seastrjs) > -1);
                    })
                } else {
                    return pro.seljs;
                }
            }
        },
        methods: {
            dykcmd: function () {
                var pro = this;
                var ids = [];
                for (var i = 0; i < this.tableop.multipleSelection.length; i++) {
                    ids.push(this.tableop.multipleSelection[i].bkjse);
                }
                if (ids.length == 0) {
                    this.$notify.error({
                        title: '错误',
                        message: '至少需要选择一条数据才能操作'
                    });
                    return;
                }
                $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_GETKCMDPDF', { xq: pro.query.xq.value, kslb: pro.query.lx, P1: ids.join(), P2: pro.selsj.sj, sj: pro.selsj.sjxx }, function (resultData) {
                    if (!resultData.ErrorMsg) {
                        var furl = resultData.Result;
                        top.ComFunJS.winviewform("/ToolS/pdfjs-2.6.347-dist/web/viewer.html?file=" + furl, '打印报表', "1000", "");
                    }
                })
            },
            filterTag(value, row) {
                return row.zt == value;
            },
            selchangesj: function (rowdata) {
                var pro = this;
                pro.selsj = rowdata;
                pro.tableop.dataset = [];
                if (rowdata.sjxx) {
                    var tempdatas = pro.alldata.filter(data => {
                        var bl = false;
                        if (data["sj"] == rowdata.sjxx) {
                            bl = true;
                        }
                        return bl;
                    })
                    pro.tableop.dataset = tempdatas;
                }
            },
            addjkls: function () {
                var pro = this;
                _.forEach(pro.js.value, function (js) {
                    if (_.findIndex(pro.seljs, function (obj) {
                        return obj.jsdm == js[1];
                    }) >= -1) {
                        pro.seljs.push({ jsdm: js[1], jsmc: "", jkcs: "0" });
                    }
                })
                var jsdm = "";
                _.forEach(pro.seljs, function (js) {
                    jsdm = jsdm + js.jsdm + ",";
                })
                $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_GETKXLS', { xq: pro.query.xq.value, kslb: pro.query.lx, jsdm: jsdm }, function (resultData) {
                    if (!resultData.ErrorMsg) {
                        pro.seljs = resultData.Result;
                        pro.js.value = [];

                    }
                })
                pro.$notify({
                    title: '成功',
                    message: '操作成功',
                    type: 'success'
                });


            },//添加监考老师
            rychange(val) {
                this.tableop.multipleSelection = val;
            },
            funseljs: function (val) {
                this.jsks = val;
            },
            clearjs: function (obj) {
                obj.tempjkjs = "";
                obj.tempjkjsdm = "";
            },
            dymd: function () {

                var url = "jw.yyvtc.cn/web_ksgl/web_ksgl_kasp_apdz_dy.aspx?xq=20-21-2&kssj=25,7,1,2,&jselist=267,&lb=补考&sjh=0&dyfs=1&fs=2";
            },
            deleteRow(index, rows) {
                var pro = this;
                rows.splice(index, 1);
                var jsdm = "";
                _.forEach(pro.seljs, function (js) {
                    jsdm = jsdm + js.jsdm + ",";
                })
                pro.$notify({
                    title: '成功',
                    message: '操作成功',
                    type: 'success'
                });
                $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_GETKXLS', { xq: pro.query.xq.value, kslb: pro.query.lx, jsdm: jsdm }, function (resultData) {
                    if (!resultData.ErrorMsg) {

                    }
                })
            },
            apks: function () {
                var pro = this;
                var ids = [];
                for (var i = 0; i < this.tableop.multipleSelection.length; i++) {
                    ids.push(this.tableop.multipleSelection[i].xh);
                }
                if (ids.length == 0) {
                    this.$notify.error({
                        title: '错误',
                        message: '至少需要选择一条数据才能操作'
                    });
                    return;
                }
                $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_GETKXLS', { xq: pro.query.xq.value, kslb: pro.query.lx, jsdm: "", P1: "Y" }, function (resultData) {
                    if (!resultData.ErrorMsg) {
                        pro.seljs = resultData.Result;
                    }
                })
                $('#DModal').modal('show');
            },
            qxjk: function () {
                var pro = this;
                if (this.tableop.multipleSelection.length == 0) {
                    this.$notify.error({
                        title: '错误',
                        message: '至少需要选择一条数据才能操作'
                    });
                    return;
                }
                pro.$confirm('是否确认要取消监考安排?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_CANCELJK', { xq: pro.query.xq.value, kslb: pro.query.lx, P1: JSON.stringify(pro.tableop.multipleSelection) }, function (resultData) {
                        if (!resultData.ErrorMsg) {
                            pro.$notify({
                                title: '成功',
                                message: '操作成功',
                                type: 'success'
                            });
                            _.forEach(pro.tableop.dataset, function (obj) {
                                obj.tempjkjs = '';
                                obj.tempjkjsdm = '';
                                obj.jkjs = '';
                                obj.jkjsdm = '';
                            })
                        }
                    })
                }).catch(() => {

                });



            },
            ksfp: function () {
                var pro = this;
                var len = pro.kcrs * 1;
                var djkkcs = _.filter(pro.tableop.multipleSelection, function (o) { return !o.tempjkjs; });
                var ls = [];
                var tempdatas = pro.alldata.filter(data => {
                    var bl = false;
                    if (data["sj"] == pro.selsj.sjxx) {
                        bl = true;
                    }
                    return bl;
                });
                _.forEach(tempdatas, function (obj) {
                    if (obj.tempjkjsdm) {
                        ls = _.concat(ls, obj.tempjkjsdm.split(","));
                    }
                });
                ls = ls.join().split(',');
                //找出已经安排的老师，避免安排冲突
                _.forEach(djkkcs, function (kc) {
                    var tempjkjs = "";
                    var tempjkjsdm = "";
                    _.forEach(pro.jsks, function (js) {
                        if (_.indexOf(ls, js.jsdm) == -1) {
                            tempjkjs = js.jsmc;
                            tempjkjsdm = js.jsdm;
                            ls.push(js.jsdm);
                            return false;
                        }
                    })
                    if (len == 2) {
                        _.forEach(pro.jsks, function (js) {
                            if (_.indexOf(ls, js.jsdm) == -1) {
                                tempjkjs = tempjkjs + "," + js.jsmc;
                                tempjkjsdm = tempjkjsdm + "," + js.jsdm;
                                ls.push(js.jsdm);
                                return false;
                            }
                        })
                    }
                    kc.tempjkjs = tempjkjs;
                    kc.tempjkjsdm = tempjkjsdm;
                });

                var nulen = _.findIndex(pro.tableop.multipleSelection, function (obj) {
                    return !obj.tempjkjs || obj.tempjkjs.split(',').length < len;
                })
                if (nulen > -1) {
                    pro.$alert('安排得老师不够哦,或者您安排的监考老师存在冲突情况!!', {
                        confirmButtonText: '确定'
                    });
                }

            },//随机分配
            SaveData: function () {
                var pro = this;
                $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_APJKLS', { xq: pro.query.xq.value, kslb: pro.query.lx, P1: JSON.stringify(pro.tableop.multipleSelection) }, function (resultData) {
                    if (!resultData.ErrorMsg) {
                        pro.$notify({
                            title: '成功',
                            message: '操作成功',
                            type: 'success'
                        });
                        _.forEach(pro.tableop.multipleSelection, function (obj) {
                            obj.jkjs = obj.tempjkjs;
                            obj.jkjsdm = obj.tempjkjsdm;

                        })
                        $('#DModal').modal('hide');

                    }
                })
            },
            querydata: function () {
                var pro = this;
                pro.loading = true;
                pro.alldata = [];
                pro.sjdata = [];
                pro.tableop.dataset = [];
                pro.rselsj = "";
                $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_GETJKKCDATA', { P1: "1", xq: pro.query.xq.value, xb: pro.query.xb.value.join(), kslb: pro.query.lx.value, xiaoq: pro.query.xiaoq.value  }, function (resultData) {
                    if (!resultData.ErrorMsg) {
                        pro.alldata = resultData.Result;
                        pro.sjdata = resultData.Result1;
                        pro.loading = false;

                    }
                })



            }

        },
        watch: {
            'query': { //深度监听，可监听到对象、数组的变化
                handler(newV, oldV) {
                    var chi = this;
                    if (newV) {
                        if (chi.query.xb.value.length > 0) {
                            chi.querydata();
                        }
                    }
                },
                deep: true
            },
            'lsxb': { //深度监听，可监听到对象、数组的变化
                handler(newV, oldV) {
                    var pro = this;
                    if (newV) {
                        if (pro.selsj.sj) {
                            $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_GETKXLS', { xq: pro.query.xq.value, xbdm: pro.lsxb.value, kslb: pro.query.lx, kssj: pro.selsj.sj }, function (resultData) {
                                if (!resultData.ErrorMsg) {
                                    pro.jsdata = resultData.Result;

                                }
                            })
                        }

                    }
                },
                deep: true
            }
        },
        mounted: function () {
            var pro = this;
            pro.$nextTick(function () {

            })

        }
    };
</script>